package controlers;

import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import models.Banda;
import models.Usuario;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class FanControler extends ActionSupport 
{
	private String nomeBand;
	List<String> bands;
	@SuppressWarnings("unchecked")
	@Override
	public String execute()
	{
		Usuario fan;
		fan = (Usuario)ActionContext.getContext().getSession().get("login");
		Map<String,Banda> bandas = (Map<String,Banda>)ActionContext.getContext().getApplication().get("Bandas");
		if(bandas==null) {
			return "fail";
		}
		bands = new LinkedList<String>();
		for(Banda x : fan.getBandasFav())
		{
			bands.add(x.getNome());
		}
		Banda banda = bandas.get(nomeBand);
		if(fan==null || banda==null) {
			return "fail";
		}
		bands.add(nomeBand);
		fan.becomeFanOf(banda);
		return "sucess";
	}

	public String getNomeBand() {
		return nomeBand;
	}
	public void setNomeBand(String nomeBand) {
		this.nomeBand = nomeBand;
	}

	public List<String> getBands() {
		return bands;
	}

	public void setBands(List<String> bands) {
		this.bands = bands;
	}

}
